package com.gxa.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.admin.entity.Orders;
import com.gxa.admin.mapper.OrdersMapper;
import com.gxa.admin.param.OrderParam;
import com.gxa.admin.service.OrdersService;
import com.gxa.o2o.core.dto.ResultDTO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigInteger;
import java.util.List;

/**
 * 订单表(Orders)表服务实现类
 *
 * @author makejava
 * @since 2021-07-21 22:56:59
 */
@Service("ordersService")
public class OrdersServiceImpl implements OrdersService {
    @Resource
    private OrdersMapper ordersMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param orderId 主键
     * @return 实例对象
     */
    @Override
    public Orders queryById(BigInteger orderId) {
        return this.ordersMapper.queryById(orderId);
    }

    /**
     * 通过条件分页查询
     * @param param
     * @return
     */
    @Override
    public ResultDTO listByParam(OrderParam param){
        PageHelper.startPage(param.getPage(),param.getLimit());
        List<Orders> ordersList = ordersMapper.findByParam(param);
        PageInfo<Orders> of = PageInfo.of(ordersList);
        return new ResultDTO(200,"查询成功",of);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Orders> queryAllByLimit(int offset, int limit) {
        return this.ordersMapper.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param orders 实例对象
     * @return 实例对象
     */
    @Override
    public Orders insert(Orders orders) {
        this.ordersMapper.insert(orders);
        return orders;
    }

    /**
     * 修改数据
     *
     * @param orders 实例对象
     * @return 实例对象
     */
    @Override
    public Orders update(Orders orders) {
        this.ordersMapper.update(orders);
        return this.queryById(orders.getOrderId());
    }

    /**
     * 通过主键删除数据
     *
     * @param orderId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(BigInteger orderId) {
        return this.ordersMapper.deleteById(orderId) > 0;
    }
}
